package jiguang.ui.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.jiuyin.dianjing.R;
import com.jiuyin.dianjing.app.JGApplication;

import cn.jpush.im.android.api.model.UserInfo;
import jiguang.adapter.NotReadAdapter;
import jiguang.ui.activity.FriendInfoActivity;
import jiguang.ui.activity.GroupNotFriendActivity;
import jiguang.ui.fragment.base.BaseFragment;


/**
 * Created by ${chenyn} on 2017/9/5.
 */
public class MessageNotReadFragment extends BaseFragment {
    private Activity mContext;
    private View mRootView;
    private ListView mReceipt_noRead;
    private NotReadAdapter mAdapter;
    private long mGroupId;

    public MessageNotReadFragment(long groupIdForReceipt) {
        this.mGroupId = groupIdForReceipt;
    }

    public MessageNotReadFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.mContext = getActivity();

        initView();
        initListViewClick();
    }

    private void initListViewClick() {
        mReceipt_noRead.setOnItemClickListener((parent, view, position, id) -> {
            UserInfo userInfo = (UserInfo) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            if (userInfo.isFriend()) {
                intent.setClass(mContext, FriendInfoActivity.class);
            } else {
                intent.setClass(mContext, GroupNotFriendActivity.class);
            }
            intent.putExtra(JGApplication.TARGET_ID, userInfo.getUserName());
            intent.putExtra(JGApplication.TARGET_APP_KEY, userInfo.getAppKey());
            intent.putExtra(JGApplication.GROUP_ID, mGroupId);
            startActivity(intent);
        });
    }

    private void initView() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mRootView = LayoutInflater.from(mContext).inflate(R.layout.fragment_receipt_no_read,
                container, false);
        mReceipt_noRead = (ListView) mRootView.findViewById(R.id.receipt_noRead);
        mAdapter = new NotReadAdapter(this);
        mReceipt_noRead.setAdapter(mAdapter);
        return mRootView;
    }
}
